//
//  ThereViewController.m
//  5-24
//
//  Created by mac on 16-5-30.
//  Copyright (c) 2016年 ZHD. All rights reserved.
//

#import "ThereViewController.h"
#import "Vcf.h"

@interface ThereViewController ()
{
    NSArray *data;
}
@end

@implementation ThereViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.navigationItem.title = @"女神好美";
    self.view.backgroundColor=[UIColor redColor];
    
    // Do any additional setup after loading the view.
    NSString *path=@"/Users/mac/Desktop/5-24改/00001.vcf";
    
    NSError *err;
    NSString *vcf=[[NSString alloc] initWithContentsOfFile:path encoding:NSUTF8StringEncoding error:&err];
   
    NSMutableArray *mutArr = [NSMutableArray new];
    Vcf *man;
    NSArray *arr=[vcf componentsSeparatedByString:@"\n"];
    
    for (NSString *line in arr)
    {
        if([line hasPrefix:@"BEGIN"])
        {
            man = [Vcf new];
        }
        
        if([line hasPrefix:@"END"])
        {
            [mutArr addObject:man];
        }
        
        if([line hasPrefix:@"FN"])
        {
            NSArray *arr1=[line componentsSeparatedByString:@":"];
            
            NSString *name=[arr1[1] stringByReplacingOccurrencesOfString:@"=" withString:@"%"];
            
            name=[name stringByRemovingPercentEncoding];
            man.name = name;
            
        }
        
        
        if([line hasPrefix:@"TEL"])
        {
            NSArray *arr2=[line componentsSeparatedByString:@":"];
            man.tell = arr2[1];
        }
        
    }
    data = mutArr;



}



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return data.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil];
    Vcf *man = data[indexPath.row];
    NSLog(@"%d",indexPath.row);
    cell.textLabel.text = man.name;
    cell.detailTextLabel.text = man.tell;
    return cell;
}



- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
